#include <QtGui/QApplication>
#include <iostream>
#include "mainwindow.h"
#include "primitives.h"
#include "camera.h"
#include "pointlightsource.h"
#include "spotlightsource.h"

void montaCongresso(Scene *scene);

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Scene scene;
    ProjectionPlane pplane(-2.0, -2.0, 2.0, 2.0, 1.0);
    Camera camera(Point(3.0, 3.0, 3.0), Point(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0), pplane);
    PointLightSource light(Point(0.0, 3.0, 2.0));
    SpotLightSource spotlight1(Point(-2.0, 2.0, 2.0), Point(-1.0, 1.0, 0.0), 45.0);
    SpotLightSource spotlight2(Point(2.0, 0.0, 3.0), Point(2.0, 3.0, 3.0), 45.0);
    Cube *cube = new Cube();
    CgMaterial corconcreto(CgColor(0.5, 0.5, 0.5), CgColor(0.5, 0.5, 0.5), CgColor(0.0, 0.0, 0.0));

    cube->multiplyCurrentTransformation(Matrix::scalingMatrix(1.5, 1.5, 1.5));
//    cube->multiplyCurrentTransformation(Matrix::xRotationMatrix(30.0));
//    cube->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 0.0, -2.0));
    cube->set_material(corconcreto);
    Hemisphere *h = new Hemisphere();

//    h->multiplyCurrentTransformation(Matrix::scalingMatrix(2.0, 2.0, 2.0));
//    h->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 0.0, -2.0));
//    h->multiplyCurrentTransformation(Matrix::yRotationMatrix(180.0));
    h->set_material(corconcreto);
    Rectangle *r = new Rectangle(Point(-1.0, -1.0, -2.0), Point(1.0, -1.0, -2.0), Point(1.0, 1.0, -2.0), Point(-1.0, 1.0, -2.0));
    r->set_material(corconcreto);
//    scene.addObject(h);
//    scene.addObject(r);
//    scene.addObject(cube);
    scene.set_background_color(CgColor(0.0, 0.7, 0.7));
    //scene.set_ambient(CgColor(0.7, 0.7, 0.7));
    scene.set_ambient(CgColor(0.5, 0.5, 0.5));

    light.set_ambient(CgColor(0.6, 0.6, 0.6));
    light.set_diffuse(light.ambient());
    light.set_specular(CgColor(0.1, 0.1, 0.1));
    spotlight1.set_ambient(CgColor(1.0, 1.0, 1.0));
    spotlight1.set_diffuse(light.ambient());
    spotlight1.set_specular(CgColor(0.4, 0.4, 0.4));
    spotlight2.set_ambient(CgColor(1.0, 1.0, 1.0));
    spotlight2.set_diffuse(light.ambient());
    spotlight2.set_specular(CgColor(0.1, 0.1, 0.1));
    montaCongresso(&scene);
    scene.addLightSource(&light);
    scene.addLightSource(&spotlight1);
//    scene.addLightSource(&spotlight2);
    scene.setCamera(camera);
    MainWindow w(&scene);
    w.show();
    return a.exec();
}

void montaCongresso(Scene *scene)
{
    Hemisphere *hemisferio_esquerdo = new Hemisphere();
    Hemisphere *hemisferio_direito = new Hemisphere();
    Rectangle *grama = new Rectangle(Point(-1.0, 0.0, -1.0), Point(-1.0, 0.0, 1.0), Point(1.0, 0.0, 1.0), Point(1.0, 0.0, -1.0));
    Cube *placa1 = new Cube();
    Cube *placa2 = new Cube();
    Cube *torre_esquerda = new Cube();
    Cube *torre_direita = new Cube();
    Cube *ponte = new Cube();
    Cube *inicio_rampa = new Cube();
    Cube *subida_rampa = new Cube();
    Cube *fim_rampa = new Cube();
    Cube *chao = new Cube();

    CgMaterial corgrama(CgColor(0.0, 0.4, 0.0), CgColor(0.0, 0.4, 0.0), CgColor(0.0, 0.0, 0.0));
    CgMaterial corconcreto(CgColor(0.5, 0.5, 0.5), CgColor(0.2, 0.2, 0.2), CgColor(0.0, 0.0, 0.0));

    hemisferio_esquerdo->multiplyCurrentTransformation(Matrix::xRotationMatrix(90.0));
    hemisferio_esquerdo->multiplyCurrentTransformation(Matrix::translationMatrix(-2.0, 1.0, 0.0));

    hemisferio_direito->multiplyCurrentTransformation(Matrix::xRotationMatrix(-90.0));
    hemisferio_direito->multiplyCurrentTransformation(Matrix::translationMatrix(2.0, 2.0, 0.0));

    grama->multiplyCurrentTransformation(Matrix::scalingMatrix(15.0, 0.0, 15.0));
    grama->set_material(corgrama);

    placa1->multiplyCurrentTransformation(Matrix::scalingMatrix(6.5, 0.05, 3.0));
    placa1->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 0.2, 0.0));
    placa1->set_material(corconcreto);

    placa2->multiplyCurrentTransformation(Matrix::scalingMatrix(6.5, 0.05, 3.0));
    placa2->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 1.0, 0.0));
    placa2->set_material(corconcreto);

    torre_esquerda->multiplyCurrentTransformation(Matrix::scalingMatrix(0.5, 5.0, 1.0));
    torre_esquerda->multiplyCurrentTransformation(Matrix::translationMatrix(-0.5, 3.5, 0.0));
    torre_esquerda->set_material(corconcreto);

    torre_direita->multiplyCurrentTransformation(Matrix::scalingMatrix(0.5, 5.0, 1.0));
    torre_direita->multiplyCurrentTransformation(Matrix::translationMatrix(0.5, 3.5, 0.0));
    torre_direita->set_material(corconcreto);

    ponte->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 4.2, 0.0));
    ponte->set_material(corconcreto);

    inicio_rampa->multiplyCurrentTransformation(Matrix::scalingMatrix(1.0, 0.05, 1.1));
    inicio_rampa->multiplyCurrentTransformation(Matrix::xRotationMatrix(12.0));
    inicio_rampa->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 0.1, 4.9));
    inicio_rampa->set_material(corconcreto);

    subida_rampa->multiplyCurrentTransformation(Matrix::scalingMatrix(0.5, 0.04, 2.0));
    subida_rampa->multiplyCurrentTransformation(Matrix::xRotationMatrix(21.0));
    subida_rampa->multiplyCurrentTransformation(Matrix::translationMatrix(-0.25, 0.6, 2.5));
    subida_rampa->set_material(corconcreto);

    fim_rampa->multiplyCurrentTransformation(Matrix::scalingMatrix(1.0, 0.05, 3.0));
    fim_rampa->multiplyCurrentTransformation(Matrix::translationMatrix(0.0, 0.2, 2.9));
    fim_rampa->set_material(corconcreto);

    chao->multiplyCurrentTransformation(Matrix::scalingMatrix(30.0, 0.05, 30.0));
    chao->set_material(corgrama);

    scene->addObject(hemisferio_esquerdo);
    scene->addObject(hemisferio_direito);
//    scene->addObject(chao);
    scene->addObject(placa1);
    scene->addObject(placa2);
    scene->addObject(torre_esquerda);
    scene->addObject(torre_direita);
    scene->addObject(ponte);
    scene->addObject(inicio_rampa);
    scene->addObject(subida_rampa);
    scene->addObject(fim_rampa);
}
